/*
 * @Author: C.
 * @Date: 2023-05-18 16:03:47
 */
import { computed } from 'vue';
import { stateEnum } from '/@/maps/index';
import { isArray } from '/@/utils/is';
// 处理单据禁用action
type IActionType = 'del' | 'edit' | 'Mps';
export function useBillState() {
  const isDisabled = computed(() => {
    return (type: IActionType, record: Recordable | Recordable[]) => {
      if (isArray(record)) {
        if (record.length == 0) return true;
        return record.some((item) => {
          const options = stateEnum.getItem(item.State)?.options;
          return !options[type];
        });
      } else {
        const options = stateEnum.getItem(record.State)?.options;
        return !options[type];
      }
    };
  });
  return {
    isDisabled,
  };
}
